﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
namespace DAL
{
    public class AchileDal
    {
        DBHelper db = new DBHelper();
        public List<AchileModel> GetListAll()
        {
            string sql = $"select * from [dbo].[Achilve]";
            List<AchileModel> list = new List<AchileModel>();
            DataTable dt = db.GetData(sql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                AchileModel DM = new AchileModel();
                DM.ID = Convert.ToInt32(dt.Rows[i]["ID"].ToString());
                DM.StudentNames = dt.Rows[i]["StudentNames"].ToString();
                DM.StudentIDs = Convert.ToInt32(dt.Rows[i]["StudentIDs"].ToString());
                DM.StudentSubject = dt.Rows[i]["StudentSubject"].ToString();
                DM.StudentAchilve = Convert.ToInt32(dt.Rows[i]["StudentAchilve"].ToString());
                DM.StudentHG = dt.Rows[i]["StudentHG"].ToString();
                list.Add(DM);
            }
            return list;
        }
        public bool Update(AchileModel PM)
        {
            string sql = $"update [dbo].[Achilve] set StudentHG='{PM.StudentHG}' where ID='{PM.ID}'";
            if (db.SetData(sql))
            {
                return true;
            }
            else
            {

                return false;
            }
        }

        public List<AchileModel> GetListAllk()
        {
            string sql = $"select * from [dbo].[TimeTable]";
            List<AchileModel> list = new List<AchileModel>();
            DataTable dt = db.GetData(sql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                AchileModel DM = new AchileModel();
                DM.TID = Convert.ToInt32(dt.Rows[i]["TID"].ToString());
                DM.DutyDay = dt.Rows[i]["DutyDay"].ToString();
                DM.TA = dt.Rows[i]["TA"].ToString();
                DM.CA = dt.Rows[i]["CA"].ToString();
                DM.TB = dt.Rows[i]["TB"].ToString();
                DM.CB = dt.Rows[i]["CB"].ToString();
                DM.TC = dt.Rows[i]["TC"].ToString();
                DM.CC = dt.Rows[i]["CC"].ToString();
                DM.TD = dt.Rows[i]["TD"].ToString();
                DM.CD = dt.Rows[i]["CD"].ToString();
                DM.TE = dt.Rows[i]["TE"].ToString();
                DM.CE = dt.Rows[i]["CE"].ToString();
                list.Add(DM);
            }
            return list;
        }


        public List<AchileModel> GetListAllY()
        {
            string sql = $"select * from [dbo].[StudentLeave]";
            List<AchileModel> list = new List<AchileModel>();
            DataTable dt = db.GetData(sql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                AchileModel DM = new AchileModel();
                DM.StuID = Convert.ToInt32(dt.Rows[i]["StuID"].ToString());
                DM.StudentName = dt.Rows[i]["StudentName"].ToString();
                DM.StudentID = Convert.ToInt32(dt.Rows[i]["StudentID"].ToString());
                DM.StudentEvent = dt.Rows[i]["StudentEvent"].ToString();
                DM.LeaveTime = dt.Rows[i]["LeaveTime"].ToString();
                DM.LeaveApprove = Convert.ToInt32(dt.Rows[i]["LeaveApprove"].ToString());
                list.Add(DM);
            }
            return list;
        }

        public bool Updates(AchileModel PM)
        {
            string sql = $"update [dbo].[StudentLeave] set [LeaveApprove]='{PM.LeaveApprove}' where StuID='{PM.StuID}'";
            if (db.SetData(sql))
            {
                return true;
            }
            else
            {

                return false;
            }
        }

        public List<AchileModel> GetListAllT()
        {
            string sql = $"select * from [dbo].[TeacherLeave]";
            List<AchileModel> list = new List<AchileModel>();
            DataTable dt = db.GetData(sql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                AchileModel DM = new AchileModel();
                DM.TeachID = Convert.ToInt32(dt.Rows[i]["TeachID"].ToString());
                DM.TeacherName = dt.Rows[i]["TeacherName"].ToString();
                DM.TeacherEvent = dt.Rows[i]["TeacherEvent"].ToString();
                DM.TeacherLeaveTime = dt.Rows[i]["TeacherLeaveTime"].ToString();
                DM.StudentLeaveApprove = Convert.ToInt32(dt.Rows[i]["StudentLeaveApprove"].ToString());
                list.Add(DM);
            }
            return list;
        }

        public bool Updatet(AchileModel PM)
        {
            string sql = $" update [dbo].[TeacherLeave] set StudentLeaveApprove='{PM.StudentLeaveApprove}' where TeachID='{PM.TeachID}'";
            if (db.SetData(sql))
            {
                return true;
            }
            else
            {

                return false;
            }
        }
        public bool updateA(AchileModel PM)
        {
            string sql = $" update [dbo].[TimeTable] set CA='{PM.CA}',CB='{PM.CB}',CC='{PM.CC}',CD='{PM.CD}',CE='{PM.CE}'where TID='{PM.TID}'";
            if (db.SetData(sql))
            {
                return true;
            }
            else
            {

                return false;
            }
        }
    }
}
